package com.css.dzj.zfjg.modules.feedbackrelate.Controller;


import com.css.aq.server.service.BaseService;
import com.css.dzj.zfjg.common.util.BeanUtil;
import com.css.dzj.zfjg.common.util.R;
import com.css.dzj.zfjg.modules.feedbackrelate.Service.JgLhjgRwfkglService;
import com.css.dzj.zfjg.modules.feedbackrelate.entity.JgLhjgRwfkglEntity;
import com.querydsl.core.QueryResults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 联合监管任务反馈关联表
 *
 */
@RestController
@RequestMapping("generator/jglhjgrwfkgl")
public class JgLhjgRwfkglController {
    @Autowired
    private JgLhjgRwfkglService jgLhjgRwfkglService;

    @Autowired
    private BaseService baseService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam(name = "pageSize" ,required = false)Integer pageSize,
                  @RequestParam(name = "pageNo" ,required = false)Integer pageNo){
        //Integer pageSize = (Integer) params.get("pageSize");
        //Integer pageNo =  (Integer) params.get("pageNo");
        try {
            PageRequest pageRequest = PageRequest.of(pageNo-1, pageSize);
            QueryResults page = jgLhjgRwfkglService.queryPage(pageRequest);
            baseService.logSuccess(3, "分页查询联合监管任务反馈关联信息成功", "2");
            return R.ok().put("page", page);
        } catch (Exception e) {
            e.printStackTrace();
            baseService.logFailed(3, "分页查询联合监管任务反馈关联信息失败", "2");
            return R.error(e.getMessage());
        }

    }

    /**
     * 根据任务编码查询监管行为
     * @param taskNo
     * @return
     */
    public List<JgLhjgRwfkglEntity> findListByTaskNo(String taskNo, String superviseItemCode) {
        List<JgLhjgRwfkglEntity> lhjgRwfkglEntities = jgLhjgRwfkglService.findListByTaskNo(taskNo,superviseItemCode);
        baseService.logSuccess(3, "根据任务编码查询监管行为信息成功", "2");
        return lhjgRwfkglEntities;
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{taskno}")
    public R info(@PathVariable("taskno") String taskno){
        try {
            JgLhjgRwfkglEntity jgLhjgRwfkgl = jgLhjgRwfkglService.getById(taskno);
            baseService.logSuccess(3, "通过任务编码获取联合监管任务反馈关联信息成功", "2");
            return R.ok().put("jgLhjgRwfkgl", jgLhjgRwfkgl);
        } catch (Exception e) {
            e.printStackTrace();
            baseService.logFailed(3, "通过任务编码获取联合监管任务反馈关联信息失败", "2");
            return R.error(e.getMessage());
        }

    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody JgLhjgRwfkglEntity jgLhjgRwfkgl){
        try {
            jgLhjgRwfkglService.save(jgLhjgRwfkgl);
            baseService.logSuccess(3, "联合监管任务反馈关联信息添加成功", "2");
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            baseService.logFailed(3, "联合监管任务反馈关联信息添加失败", "2");
            return R.error(e.getMessage());
        }

    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody JgLhjgRwfkglEntity jgLhjgRwfkgl){
        try {
            JgLhjgRwfkglEntity jrg = jgLhjgRwfkglService.getById(jgLhjgRwfkgl.getTaskno());
            BeanUtil.copyBeanNotNullToBean(jgLhjgRwfkgl, jrg);
            baseService.logSuccess(3, "联合监管任务反馈关联信息修改成功", "2");
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            baseService.logFailed(3, "联合监管任务反馈关联信息修改失败", "2");
            return R.error(e.getMessage());
        }

    }

    /**
     * 根据任务编码和反馈ID查询监管行为
     * @param taskNo
     * @return
     */
    public JgLhjgRwfkglEntity findOneByTaskNo(String taskNo, String superviseItemCode,String uuid) {
        JgLhjgRwfkglEntity lhjgRwfkglEntitie = jgLhjgRwfkglService.findOneByTaskNo(taskNo,superviseItemCode,uuid);
        return lhjgRwfkglEntitie;
    }

}
